import Vue from 'vue'
import Vuex from 'vuex'

Vue.use(Vuex)

const store = new Vuex.Store({
	state: {
		hasLogin: false, //验证是否登录
		userInfo: {}, //用户信息
		hasOpenid: false,
		userOpenid: {}
	},
	mutations: {
		//登录
		login(state, provider) {
			console.log("222222");
			state.hasLogin = true;
			state.userInfo = provider;
			uni.setStorage({ //缓存用户登陆状态
				key: 'userInfo',
				data: provider
			})
			console.log(state.userInfo);
			
		},
		//退出登录
		logout(state) {
			state.hasLogin = false;
			state.userInfo = {};
			uni.removeStorage({
				key: 'userInfo'
			})
		},
		setOpenid(state, provider) {

			state.hasOpenid = true;
			state.userOpenid = provider;
			uni.setStorage({ //缓存用户登陆状态
				key: 'openid',
				data: provider
			})
			console.log(state.userOpenid);
		}
	},
	actions: {

	}
})

export default store
